<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Embedding classes</title>
</head>
<body>
    <h3>Embedded Classes or Components</h3>
    <p>In object-modeling terms, aggregation (or composition) represents stronger form of association between two objects. It's <em>a part-of</em> relationship where parts are dependent on whole and their lifecycle is fully owned by the whole. Taking an example, let's say we are modeling an employee and his address. Address has no independent existence and will be removed if employee is removed from the system. Aggregation relationships almost always are candidates for embedded mapping.
    </p>
    <p>
    <em>Embedded mapping</em> is a JPA2 terminology and it's equivalent in Hibernate terms is <em>Component mapping</em>. Java has no concept of composition. A class or attribute can’t be marked as a component or composition. The only difference is the object identifier - a component has no individual identity, hence the persistent component class requires no identifier property or identifier mapping. It’s a simple POJO. In the database, however, the state of the embedded object is stored with the rest of the entity state in the database row, with no distinction between the state in the Java entity and that in its embedded object. The embedded objects are marked using <em>@Embedded</em> annotation on corresponding getter or field in parent entity. Also, embeddable object is marked with <em>@Embeddable</em> annotation at the class level. Embeddable objects will use the usual JPA2 annotations to provide column mapping metadata.
    </p>
</body>
</html>
